from flask_restx import Namespace, Resource
from app import db
from app.models.department import Department

ns = Namespace('departments', description='部门管理')

@ns.route('/')
class DepartmentList(Resource):
    def get(self):
        departments = Department.query.all()
        return {'departments': [dept.to_dict() for dept in departments]}

@ns.route('/<int:id>')
class DepartmentDetail(Resource):
    def get(self, id):
        dept = Department.query.get_or_404(id)
        return dept.to_dict()